package edu.gduf.service.impl;

import edu.gduf.dao.StudentDao;
import edu.gduf.domain.ResultInfo;
import edu.gduf.service.PersonalShowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Demo Class
 *
 * @author 古市
 * @date 2020-03-27 15:20
 **/
@Service
public class PersonalShowServiceImpl implements PersonalShowService {

    private StudentDao dao;

    @Resource
    public void setDao(StudentDao dao) {
        this.dao = dao;
    }

    @Override
    public ResultInfo getInformationByNum(String num){
        return ResultInfo.successInfo("", dao.findStudentByNum(num));
    }

    @Override
    public ResultInfo getMembers(String branch, String stage,int page, String profession, String classNum) {

        Map<String, Object> map = new HashMap<>();
        //查找页面,查找页面的条数，即列表的长度
        int number=dao.findMembersNum(branch, stage, profession, classNum);
        map.put("totalCount", number);

        //页面的页数
        if (number%15==0) {
            map.put("totalPage", number/15);
        } else {
            map.put("totalPage",number/15+1);
        }

        map.put("result", dao.findMembers(branch, stage, profession, classNum, (page-1) * 15));

        return ResultInfo.successInfo("success", map);
    }

    @Override
    public ResultInfo getClassNum(String profession) {
        return ResultInfo.successInfo("成功获取班级号", dao.findClassNum(profession));
    }

    @Override
    public ResultInfo getProfession(String branch) {
        return ResultInfo.successInfo("成功获取专业", dao.findProfession(branch));
    }

}
